public class demo1 {
    public boolean backspaceCompare(String s, String t) {
        return ret(s).equals(ret(t));
    }
    public String ret(String x){
        StringBuilder stringBuilder=new StringBuilder();
        for (int i = 0; i <x.length() ; i++) {
            if(stringBuilder.length()>0&&x.charAt(i)=='#')stringBuilder.deleteCharAt(stringBuilder.length()-1);
            else {
                if(x.charAt(i)!='#')stringBuilder.append(x.charAt(i));
            }
        }
        return stringBuilder.toString();
    }
}
